package com.ccys.cms.controller.productAndService;


import com.ccys.cms.service.productAndService.ProductTypeService;
import com.ccys.common.vo.ResponseResult;
import com.ccys.db.dto.web.productAndService.NumEnum;
import com.ccys.db.dto.web.productAndService.ProductTypeDto;
import com.ccys.db.entity.TblProductType;
import com.ccys.db.mapper.TblProductTypeMapper;
import com.ccys.db.vo.web.productAndService.IdNameVo;
import com.ccys.db.vo.web.productAndService.ProductTypeVo;
import com.github.pagehelper.PageInfo;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.List;

@Slf4j
@RestController
@RequestMapping("/productAndService")
@Api(tags = "产品类型管理")
public class ProductTypeController {


    @Resource
    private ProductTypeService service;


    @Resource
    private TblProductTypeMapper mapper;


    @PostMapping("productType")
    @ApiOperation("新增")
    @Transactional
    public ResponseResult insert(TblProductType model) {

        int i = service.insertOrUpdate(model);
        return ResponseResult.update(i);
    }


    @PutMapping("productType")
    @ApiOperation("修改")
    @Transactional
    public ResponseResult update(TblProductType model) {

        int i = service.insertOrUpdate(model);
        return ResponseResult.update(i);
    }






    @DeleteMapping("productType")
    @ApiOperation("根据Id删除")
    @Transactional
    public ResponseResult delete(String id) {

        TblProductType model = new TblProductType();
        model.setId(id);
        model.setDelFlag(NumEnum.DEL.getCode());
        int i = service.updateEntityById(model);
        return ResponseResult.update(i);
    }


    @GetMapping("productType")
    @ApiOperation(value = "查询分页", notes = "排序字段 t1.status /t2. user_fullname / t1.created_on")
    public ResponseResult<PageInfo<ProductTypeVo>, Object> getPage(ProductTypeDto dto) {

        return service.getPage(dto);
    }



    @GetMapping("productType/list")
    @ApiOperation("查询productType集合")
    public ResponseResult<List<IdNameVo>,Object> getList(){
        List<IdNameVo> list = mapper.getProductTypeList();
        return ResponseResult.success(list);
    }

}
